package com.admin.web.controller;

import com.admin.web.uresponse.OBGUserResponse;
import com.bayss.core.constant.ResultMsg;
import com.bayss.core.entity.grade.Grade;
import com.bayss.core.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 评分管理
 */
@RestController
public class GradeController extends ApiBaseController {
    @Autowired
    private GradeService gradeService;

    /**
     * 查询
     */
    @RequestMapping(value = "/grade/list.json")
    public ResultMsg list() {
        return ResultMsg.success(gradeService.list());
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/grade/delete.json")
    public ResultMsg deleteById(Integer id) {
        return gradeService.delete(id);
    }

    /**
     * 新增
     *
     * @return
     */
    @RequestMapping(value = "/grade/add.json")
    public ResultMsg add(OBGUserResponse obgUserResponse, String gradeItem, Integer weight) {
        Grade grade = new Grade();
        grade.setOperateId(obgUserResponse.getUid());
        grade.setWeight(weight);
        grade.setGradeItem(gradeItem);
        grade.setItemType(0);
        return gradeService.saveGrade(grade);
    }

    /**
     * 更新
     */
    @RequestMapping(value = "/grade/update.json")
    public ResultMsg update(OBGUserResponse obgUserResponse, Integer id, String gradeItem, Integer weight) {
        Grade grade = new Grade();
        grade.setId(id);
        grade.setOperateId(obgUserResponse.getUid());
        grade.setWeight(weight);
        grade.setGradeItem(gradeItem);
        return gradeService.updateGrade(grade);
    }


}
